using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class UniversalIDTypeAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public UniversalIDTypeAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v23] = HL7TableType.User;
						tableVersionTypes[HL7Version.v231] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v24] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v25] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v251] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v26] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v27] = HL7TableType.HL7;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v23] = new string[]{""};
						validVersionCodes[HL7Version.v231] = new string[]{"DNS","GUID","HCD","HL7","ISO","L,M,N","Random","UUID","x400","x500"};
						validVersionCodes[HL7Version.v24] = new string[]{"DNS","GUID","HCD","HL7","ISO","L,M,N","Random","UUID","x400","x500"};
						validVersionCodes[HL7Version.v25] = new string[]{"DNS","GUID","HCD","HL7","ISO","L,M,N","Random","URI","UUID","x400","x500"};
						validVersionCodes[HL7Version.v251] = new string[]{"DNS","GUID","HCD","HL7","ISO","L,M,N","Random","URI","UUID","x400","x500"};
						validVersionCodes[HL7Version.v26] = new string[]{"DNS","GUID","HCD","HL7","ISO","L,M,N","Random","URI","UUID","x400","x500"};
						validVersionCodes[HL7Version.v27] = new string[]{"DNS","EUI64","CLIA","CLIP","GUID","HCD","HL7","ISO","L,M,N","Random","URI","UUID","x400","x500"};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v23] = new string[]{""};
						validVersionDescriptions[HL7Version.v231] = new string[]{"An Internet dotted name. Either in ASCII or as integers","Same as UUID.","The CEN Healthcare Coding Scheme Designator. (Identifiers used in DICOM follow this assignment scheme.)","Reserved for future HL7 registration schemes","An International Standards Organization Object Identifier","These are reserved for locally defined coding schemes.","Usually a base64 encoded string of random bits.  The uniqueness depends on the length of the bits.  Mail systems often generate ASCII string  \"unique names,\" from a  combination of random bits and system names.  Obviously, such identifiers will not be con","The DCE Universal Unique Identifier","An X.400 MHS format identifier","An X.500 directory name"};
						validVersionDescriptions[HL7Version.v24] = new string[]{"An Internet dotted name. Either in ASCII or as integers","Same as UUID.","The CEN Healthcare Coding Scheme Designator. (Identifiers used in DICOM follow this assignment scheme.)","Reserved for future HL7 registration schemes","An International Standards Organization Object Identifier","These are reserved for locally defined coding schemes.","Usually a base64 encoded string of random bits.   The uniqueness depends on the length of the bits.  Mail systems often generate ASCII string  \"unique names,\" from a combination of random bits and system names.  Obviously, such identifiers will not be con","The DCE Universal Unique Identifier","An X.400 MHS format identifier","An X.500 directory name"};
						validVersionDescriptions[HL7Version.v25] = new string[]{"An Internet dotted name. Either in ASCII or as integers","Same as UUID.","The CEN Healthcare Coding Scheme Designator. (Identifiers used in DICOM follow this assignment scheme.)","Reserved for future HL7 registration schemes","An International Standards Organization Object Identifier","These are reserved for locally defined coding schemes.","Usually a base64 encoded string of random bits.","Uniform Resource Identifier","The DCE Universal Unique Identifier","An X.400 MHS format identifier","An X.500 directory name"};
						validVersionDescriptions[HL7Version.v251] = new string[]{"An Internet dotted name. Either in ASCII or as integers","Same as UUID.","The CEN Healthcare Coding Scheme Designator. (Identifiers used in DICOM follow this assignment scheme.)","Reserved for future HL7 registration schemes","An International Standards Organization Object Identifier","These are reserved for locally defined coding schemes.","Usually a base64 encoded string of random bits.<p>The uniqueness depends on the length of the bits. Mail systems often generate ASCII string âunique names,\" from a combination of random bits and system names. Obviously, such identifiers will not be cons","Uniform Resource Identifier","The DCE Universal Unique Identifier","An X.400 MHS format identifier","An X.500 directory name"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"An Internet dotted name. Either in ASCII or as integers","Same as UUID.","The CEN Healthcare Coding Scheme Designator. (Identifiers used in DICOM follow this assignment scheme.)","Reserved for future HL7 registration schemes","An International Standards Organization Object Identifier","These are reserved for locally defined coding schemes.","Usually a base64 encoded string of random bits.<p>The uniqueness depends on the length of the bits. Mail systems often generate ASCII string \"unique names,\" from a combination of random bits and system names. Obviously, such identifiers will not be constr","Uniform Resource Identifier","The DCE Universal Unique Identifier","An X.400 MHS format identifier","An X.500 directory name"};
						validVersionDescriptions[HL7Version.v27] = new string[]{"An Internet host name, in accordance with RFC 1035; or an IP address. Either in ASCII or as integers, with periods between components (\"dotted\" notation).","IEEE 64-bit Extended Unique Identifier is comprised of a  24-bit company identifier and a 40-bit instance identifier.  The value shall be formatted as 16 ASCII HEX digits, for example, \"AABBCC1122334455\".  The 24-bit company identifier, formally known as ","Clinical Laboratory Improvement Amendments. Allows for the ability to designate organization identifier as a \"CLIA\" assigned number (for labs)","Clinical laboratory Improvement Program. Allows for the ability to designate organization identifier as a \"CLIP\" assigned number (for labs).Â  Used by US Department of Defense.","Same as UUID.","The CEN Healthcare Coding Scheme Designator","HL7 registration schemes","An International Standards Organization Object Identifier (OID), in accordance with ISO/IEC 8824.  Formatted as decimal digits separated by periods; recommended limit of 64 characters","Locally defined coding entity identifier.","Usually a base64 encoded string of random bits.<p>Note: Random IDs are typically used for instance identifiers, rather than an identifier of an Assigning Authority that issues instance identifiers","Uniform Resource Identifier","The DCE Universal Unique Identifier, in accordance with RFC 4122. Recommended format is 32 hexadecimal digits separated by hyphens, in the digit grouping 8-4-4-4-12","An X.400 MHS identifier. Recommended format is in accordance with RFC 1649","An X.500 directory name"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
